package com.cyt.sys.service.impl;

import com.cyt.base.model.dto.ReturnResult;
import com.cyt.sys.dao.SysLogLoginDao;
import com.cyt.sys.model.po.SysLogLogin;
import com.cyt.sys.model.vo.SysLogLoginVo;
import com.cyt.sys.service.SysLogLoginService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

/**
 *@Author: YuShengQiang
 *@Date: 2018-11-16 11:52
 *@Description:基础用户service实现类
 */
@Service("baseLogLoginService")
public class SysLogLoginServiceImpl extends BaseServiceImpl<SysLogLogin> implements SysLogLoginService {
    @Resource
    private SysLogLoginDao sysLogLoginDao;
    @Autowired
    public void setBaseDao(SysLogLoginDao sysLogLoginDao) {
        this.baseDao = sysLogLoginDao;
    }

   /**
    *@Author: YuShengQiang
    *@Date: 2018-11-23 14:17
    *@Description: 分页查询
    */
    public ReturnResult page(SysLogLoginVo sysLogLoginVo, int pageSize, int pageNum) {
        PageHelper.startPage(pageNum,pageSize);
        PageHelper.orderBy(" create_time desc");
        Example example = new Example(SysLogLogin.class);
        Example.Criteria criteria = example.createCriteria();
        if(StringUtil.isNotEmpty(sysLogLoginVo.getLoginName())){
            criteria.andLike("loginName","%"+ sysLogLoginVo.getLoginName()+"%");
        }
        if(StringUtil.isNotEmpty(sysLogLoginVo.getOperIp())){
            criteria.andLike("operIp","%"+ sysLogLoginVo.getOperIp()+"%");
        }
        if(StringUtil.isNotEmpty(sysLogLoginVo.getStatus())){
            criteria.andEqualTo("status", sysLogLoginVo.getStatus());
        }
        List<SysLogLogin> list= sysLogLoginDao.selectByExample(example);
        PageInfo<SysLogLogin> page=new PageInfo<SysLogLogin>(list);
        return new ReturnResult(page.getList(),page.getTotal(),page.isHasNextPage());
    }

}
